cmake_minimum_required (VERSION 3.10)
project (BRAINFLOW_GET_DATA)

set (CMAKE_CXX_STANDARD 11)
set (CMAKE_VERBOSE_MAKEFILE ON)

macro (configure_msvc_runtime)
    if (MSVC)
        # Default to statically-linked runtime.
        if ("${MSVC_RUNTIME}" STREQUAL "")
            set (MSVC_RUNTIME "static")
        endif ()
        # Set compiler options.
        set (variables
            CMAKE_C_FLAGS_DEBUG
            CMAKE_C_FLAGS_MINSIZEREL
            CMAKE_C_FLAGS_RELEASE
            CMAKE_C_FLAGS_RELWITHDEBINFO
            CMAKE_CXX_FLAGS_DEBUG
            CMAKE_CXX_FLAGS_MINSIZEREL
            CMAKE_CXX_FLAGS_RELEASE
            CMAKE_CXX_FLAGS_RELWITHDEBINFO
        )
        if (${MSVC_RUNTIME} STREQUAL "static")
            message(STATUS
                "MSVC -> forcing use of statically-linked runtime."
            )
            foreach (variable ${variables})
                if (${variable} MATCHES "/MD")
                    string (REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
                endif ()
            endforeach ()
        else ()
            message (STATUS
                "MSVC -> forcing use of dynamically-linked runtime."
            )
            foreach (variable ${variables})
                if (${variable} MATCHES "/MT")
                    string (REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
                endif ()
            endforeach ()
        endif ()
    endif ()
endmacro ()

# link msvc runtime statically
configure_msvc_runtime()

find_package (
    brainflow CONFIG REQUIRED
)

###############################
## Demo for data acquisition ##
###############################
add_executable (
    brainflow_get_data
    src/brainflow_get_data.cpp
)

target_include_directories (
    brainflow_get_data PUBLIC
    ${brainflow_INCLUDE_DIRS}
)

target_link_libraries (
    brainflow_get_data PUBLIC
    # for some systems(ubuntu for example) order matters
    ${BrainflowPath}
    ${DataHandlerPath}
    ${BoardControllerPath}
)

#############################
## Demo for file streaming ##
#############################
add_executable (
    brainflow_file_stream
    src/brainflow_file_stream.cpp
)

target_include_directories (
    brainflow_file_stream PUBLIC
    ${brainflow_INCLUDE_DIRS}
)

target_link_libraries (
    brainflow_file_stream PUBLIC
    # for some systems(ubuntu for example) order matters
    ${BrainflowPath}
    ${DataHandlerPath}
    ${BoardControllerPath}
)

#################################
## Demo for data acquisition 2 ##
#################################
add_executable (
    brainflow_get_data_twice
    src/brainflow_get_data_twice.cpp
)

target_include_directories (
    brainflow_get_data_twice PUBLIC
    ${brainflow_INCLUDE_DIRS}
)

target_link_libraries (
    brainflow_get_data_twice PUBLIC
    # for some systems(ubuntu for example) order matters
    ${BrainflowPath}
    ${DataHandlerPath}
    ${BoardControllerPath}
)

#################################
##   Demo for config_board     ##
#################################
add_executable (
    brainflow_config_board
    src/brainflow_config_board.cpp
)

target_include_directories (
    brainflow_config_board PUBLIC
    ${brainflow_INCLUDE_DIRS}
)

target_link_libraries (
    brainflow_config_board PUBLIC
    # for some systems(ubuntu for example) order matters
    ${BrainflowPath}
    ${DataHandlerPath}
    ${BoardControllerPath}
)